package Test;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import Controller.DBAccess;
import Controller.RideInfo;
import Model.Escort;
import Model.Kid;

public class DBAccessDriver implements DBAccess {
	private Map<Integer, Kid> kids = new HashMap<Integer, Kid>();
	private Map<Integer, Escort> escorts = new HashMap<Integer, Escort>();
	private Map<Integer, RideInfo> rides = new HashMap<Integer, RideInfo>();

	@Override
	public Kid fetchKid(int id) {
		if(!kids.containsKey(id))
			throw new IllegalArgumentException("Kid with ID " + id +
					" does not exist.");
		return kids.get(id);
	}

	@Override
	public void storeKid(Kid kid) {
		kids.put(kid.getID(), kid);
	}

	@Override
	public void deleteKid(int id) {
		if(!kids.containsKey(id))
			throw new IllegalArgumentException("Kid with ID " + id +
					" does not exist.");
		kids.remove(id);
	}

	@Override
	public Escort fetchEscort(int id) {
		if(!escorts.containsKey(id))
			throw new IllegalArgumentException("Escort with ID " + id +
					" does not exist.");
		return escorts.get(id);
	}

	@Override
	public void storeEscort(Escort escort) {
		escorts.put(escort.getID(), escort);
	}

	@Override
	public void deleteEscort(int id) {
		if(!escorts.containsKey(id))
			throw new IllegalArgumentException("Escort with ID " + id +
					" does not exist.");
		escorts.remove(id);
	}

	@Override
	public RideInfo fetchRide(int id) {
		if(!rides.containsKey(id))
			throw new IllegalArgumentException("Ride with ID " + id +
					" does not exist.");
		return rides.get(id);
	}

	@Override
	public void storeRide(RideInfo ride) {
		rides.put(ride.getID(), ride);
	}

	@Override
	public void deleteRide(int id) {
		if(!rides.containsKey(id))
			throw new IllegalArgumentException("Ride with ID " + id +
					" does not exist.");
		rides.remove(id);
	}

	@Override
	public Collection<RideInfo> fetchAllRides() {
		return rides.values();
	}
}
